package util;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.tomcat.jdbc.pool.DataSource;

public class DataSourceUtil {
	private static final DataSource dataSource = getDataSourceFromJNDI();
	
	private DataSourceUtil(){}
	
	public static DataSource getDataSource(){
		return dataSource;
	}
	
	private static DataSource getDataSourceFromJNDI(){
		Context initContext;
		DataSource ds = null;
		try {
			initContext = new InitialContext();
			ds = (DataSource) initContext.lookup("java:comp/env/jdbc/CSE");
		} catch (NamingException e) {
			System.err.println("initial context error!\n" + e);
		}
		
		return ds;
	}
	
	

}
